
import { Form as AForm, FormProps as AntdFormProps, FormItemProps } from 'antd';
import { ReactNode } from 'react';

interface FormProps extends AntdFormProps {
    children?: ReactNode;
}

function _Form(props: FormProps) {
    const { ...restProps } = props;
    return <AForm {...restProps} />
}

export const Form = Object.assign(_Form, AForm);


export function FormItem(props: FormItemProps & { render: (value?: any, onChange?: (value?: any) => void) => React.ReactNode | void | undefined }) {
    const { render, ...restProps } = props;
    return (
        <AForm.Item {...restProps} >
            <FormItemCont render={render} />
        </AForm.Item>
    )
}

/**
 * 表单项自定义渲染
 */
export function FormItemCont(props: {
    value?: any,
    onChange?: (value?: any) => void
    render: (value?: any, onChange?: (value?: any) => void) => React.ReactNode | void | undefined
}) {
    return props.render(props.value, props.onChange) || <></>;
}